package com.Controller.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sql.DAO;

import com.Model.Pojo.Users;

public class TransferAccounts extends HttpServlet {
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
    	response.setCharacterEncoding("UTF-8");
    	PrintWriter out = response.getWriter();
    	
    	String zhanghao = request.getParameter("zhanghao");
    	String jine = request.getParameter("jine");
    	
		int cunmoney = 0;
		String str;
		String style;
		String style1;
		String value;
		String source;
    	
		
    	Users usermoney = new Users();
		HttpSession session = request.getSession();
		usermoney = (Users)session.getAttribute("users");
		
		int money = usermoney.getYue();
		int cash = usermoney.getMoney();
		money += cunmoney;
		cash -= cunmoney;
		DAO dao = new DAO();
		String usersname = usermoney.getZhanghao();
		String sql = "update users set yue='" + money + "' where name='" + usersname + "' ";
		dao.xiugai(sql);
		sql = "update users set money='" + cash + "' where name='" + usersname + "' ";
		dao.xiugai(sql);
		
		usermoney.setYue(money);
		usermoney.setMoney(cash);
		session.setAttribute("users", usermoney);
		/**
		if(style.equals("0")){
			cunmoney *= -1;
		}
		DateTime date = new DateTime();
		com.sql = "insert into cunkuanqvkuan (name,money,style,date,yue)value('" + usersname + "','" + cunmoney
						+ "','" + style + "','" + date.getSettime() + "','" + money + "')";
		dao.zengjia(com.sql);//更新存款取款表
		
		com.sql = "insert into moneylist (name,style,value,date,cash,source)value('" + usersname + "','" + style1
		+ "','" + cunmoney + "','" + date.getSettime() + "','" + cash + "','" + source + "')";
		dao.zengjia(com.sql);//更新账户记录表
		
		response.sendRedirect("TransferAccounts.jsp");*/
	}

}
